﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WindowsFormsApplication1.BLL;
using Millionaire;

namespace demobackground
{
    public partial class Page1 : PhoneApplicationPage
    {
        CauHoiBLL chBLL;
        int n = 0;
        List<CauHoi> lcauhoi = new List<CauHoi>();
        public Page1()
        {
            InitializeComponent();
            chBLL = new CauHoiBLL();
            lcauhoi = chBLL.GetAll();
           // CauHoi ch = chBLL.RanDom();
            HienThiCH(lcauhoi[n]);
        }

        private void HienThiCH(CauHoi ch)
        {
            txtCauHoi.Text = ch.CauHoi1;
            btnA.Content = ch.CauA;
            btnB.Content = ch.CauB;
            btnC.Content = ch.CauC;
            btnD.Content = ch.CauD;
            
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            string dapan = lcauhoi[n].DapAn;
            int tmp = n;
            Button btn = (Button)sender;
            if (btn.Name.Equals(btnA.Name) && dapan == "A")
            {
                n++;
            }
            if (btn.Name.Equals(btnB.Name) && dapan == "B")
            {
                n++;
            }
            if (btn.Name.Equals(btnC.Name) && dapan == "C")
            {
                n++;
            }
            if (btn.Name.Equals(btnD.Name) && dapan == "D")
            {
                n++;
            }
            if (tmp == n)
            {
                MessageBox.Show("Dap an sai.Dap an dung la " + dapan);
                MessageBoxResult rs = MessageBox.Show("Ban co muon choi tiep hay khong?", "Xac nhan", MessageBoxButton.OKCancel);
                if (rs == MessageBoxResult.OK)
                {
                    HienThiCH(lcauhoi[0]);
                }
                else
                {
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                }
            }
            else
            {
                HienThiCH(lcauhoi[n]);
            }
        }

    }
}